package com.srcptit.trainning.huongpq.btvn2;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Bai1 {

    public static StringBuffer convert(long t, long b) {
        StringBuffer tmp = new StringBuffer("");
        while (t != 0) {
            if(t % b <= 9) tmp.append((t % b + ""));
            else {
                tmp.append((char)(t%b + 55)+"");
            }
            t /= b;
        }
        return tmp;
    }

    public static void main(String[] args) {
        File f = new File("bai 1.txt");
        try {
            FileReader fr = new FileReader(f);
            BufferedReader bf = new BufferedReader(fr);
            String a, a2, a3;
            long t, b;
            try {
                while ((a = bf.readLine()) != null) {
                    StringTokenizer a1 = new StringTokenizer(a);
                    a2 = a1.nextToken();
                    a3 = a1.nextToken();
                    b = 10;
                    try {
                        t = Integer.parseInt(a2);
                        b = Integer.parseInt(a3);
                        System.out.println("so " + t + " chuyen sang he " + b + " la: " + convert(t, b).reverse());
                    } catch (Exception e) {
                        System.out.println("khong the chuyen so nay.");
                    }
                }
                bf.close();
                fr.close();
            } catch (IOException ex) {
                Logger.getLogger(Bai1.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Bai1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
